package com.gopay.common.domain.send;

import com.gopay.common.constants.logging.SendType;
import com.gopay.common.constants.logging.VoType;
import com.gopay.common.domain.BaseEntity;
import com.gopay.common.hessian.SendHessianKey;

/**
 * 消息实体
 * 
 * @SendMessage.java
 * @author yaobo
 * @2013-7-18 下午05:25:35 www.gopay.com.cn Inc.All rights reserved.
 */
public class SendMessage extends BaseEntity {

    /**
     * 
     */
    private static final long serialVersionUID = 3749832641208108626L;

    private static final ThreadLocal<SendMessage> threadSendMessage = new ThreadLocal<SendMessage>();
    private static final Object object = new Object();

    public static SendMessage getSendMessage() {
        SendMessage sendMessage = threadSendMessage.get();

        synchronized (object) {
            if (sendMessage == null) {
                sendMessage = new SendMessage();
                sendMessage._key = SendHessianKey.getInstance();

                threadSendMessage.set(sendMessage);
            }
        }

        return sendMessage;
    }

    private SendMessage() {
    }

    /**
     * 发送类型
     */
    private SendType sendType;

    /**
     * 业务类型
     */
    private VoType voType;

    /**
     * 发送消息内容，一般为json串
     */
    private String data;

    /**
     * 唯一标识
     */
    private String _key;

    public String get_key() {
        return _key;
    }

    public SendType getSendType() {
        return sendType;
    }

    public void setSendType(SendType sendType) {
        this.sendType = sendType;
    }

    public VoType getVoType() {
        return voType;
    }

    public void setVoType(VoType voType) {
        this.voType = voType;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }

    @Override
    public String toString() {
        StringBuffer msg = new StringBuffer("");

        msg.append(sendType.value);
        msg.append("|");
        msg.append(voType.value);
        msg.append("|");
        msg.append(_key);
        msg.append("|");
        msg.append(data);

        return msg.toString();
    }
}
